<template>
  <div id="login">

    <div class="login_top clearfix">
      <a href="#/home" class="login_logo"><img src="../assets/images/logo02.png"></a>
    </div>

    <div class="login_form_bg">
      <div class="login_form_wrap clearfix">
        <div class="login_banner fl"></div>
        <div class="slogan fl">日夜兼程 · 急速送达</div>
        <div class="login_form fr">
          <div class="login_title clearfix">
            <h1>用户登录</h1>
            <a href="#/register">立即注册</a>
          </div>
          <div class="form_input">
            <form>
              <input type="text" name="username" v-model="user.email" class="name_input" placeholder="请输入用户名">
              <input type="password" name="password" v-model="user.password" class="pass_input" placeholder="请输入密码">
              <div class="more_input clearfix">
                <input type="checkbox" name="">
                <label>记住用户名</label>
                <a href="#">忘记密码</a>
              </div>
              <input type="submit" name="" value="登录" class="input_submit" @click.prevent="checklogin">
            </form>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { loginApi } from '@/api/Login';

export default {
  name: "Login",
  data() {
    return {
      user: {
        email: '',
        password: ''
      }

    }
  },
  methods: {
    checklogin() {
      if (this.email == '' || this.password == '') {
        alert("登录失败");
        return;
      }
      loginApi({
        "email": this.user.email,
        "password": this.user.password
      })
        .then(resp => {
          console.log(this.user.email + this.user.password);
          console.log(resp);
          if (resp.id != null) {
            // this.$setSessionStorage('user', this.user);
            window.sessionStorage.setItem('user', JSON.stringify(resp));
            console.log(sessionStorage);
            this.$router.push('/home')
          }
          else {
            console.log("error");
            return;
          }
        })
    },
    created() {
      this.$parent.ifShow = false
    }

  }
}
</script>

<style scoped>
</style>